home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-07-25 | 3.2 KB | 127 lines |
- /*
- * Tool.java - Tool selector
- * Copyright (C) 2000 Romain Guy
- * guy.romain@bigfoot.com
- * www.jext.org
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
- import waba.fx.*;
-
- /**
- * <code>Tool</code> is a tool selector. By tapping it or pressing
- * the appropriate hard key, the user can switch between available
- * tools..
- * @author Romain Guy <guy.romain@bigfoot.com>
- * @version 1.0
- */
-
- public class Tool extends Bounded
- {
- // tool to fill in the cells
- public static final byte FILLING_TOOL = 0;
- // tool to check the cells
- public static final byte HELPER_TOOL = 1;
- // tool to erase a cell
- public static final byte ERASER_TOOL = 2;
- // amount of tools
- public static final byte TOOLS_COUNT = 3;
-
- // tools pictures
- private Image[] pictures = new Image[TOOLS_COUNT];
- // selected tool
- private byte tool = FILLING_TOOL;
-
- public Tool()
- {
- for (int i = 0; i < pictures.length; i++)
- pictures[i] = new Image("datas/tool" + i + ".bmp");
- }
-
- public void free()
- {
- for (int i = 0; i < pictures.length; i++)
- pictures[i].free();
- }
-
- //////////////////////////////////
- // NOT REQUESTED YET //
- //////////////////////////////////
- // public void setTool(byte tool)
- // {
- // this.tool = tool;
- // }
- //////////////////////////////////
-
- public byte getTool()
- {
- return tool;
- }
-
- /**
- * Handles a pen down event.
- * @param x The x coordinate of the event
- * @param y The y coordinate of the event
- * @return <code>true</code> if the event can be handled
- */
-
- public boolean handlePenEvent(int x, int y)
- {
- return (x > this.x && x < (this.x + this.width) &&
- y > this.y && y < (this.y + this.height));
- }
-
- /**
- * Switches current tool going through list forward.
- */
-
- public void switchToolForward(eCross e, Graphics g)
- {
- if (++tool == TOOLS_COUNT)
- tool = FILLING_TOOL;
- paintTool(e, g);
- }
-
- /**
- * Switches current tool going through list backward.
- */
-
- public void switchToolBackward(eCross e, Graphics g)
- {
- if (--tool == -1)
- tool = ERASER_TOOL;
- paintTool(e, g);
- }
-
- private void paintTool(eCross e, Graphics g)
- {
- g.drawImage(pictures[tool], x + 3, y + 2);
- e.drawTool();
- }
-
- public void paint(Graphics g)
- {
- g.setColor(255, 255, 255);
- g.fillRect(x, y, width, height);
- g.setColor(0, 0, 0);
- g.drawRect(x, y, width, height);
-
- g.drawImage(pictures[tool], x + 3, y + 2);
- }
- }
-
- // End of Tool.java
-